from selenium import webdriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

d = webdriver.Chrome()
d.get('https://www.qq.com/')
d.maximize_window()
time.sleep(1)

wenzhang = d.find_element(By.CSS_SELECTOR, '[class=" bold"]')
wenzhang.click()
time.sleep(1)

all_windows = d.window_handles
d.switch_to.window( all_windows[1] )
time.sleep(1)
biaoti = d.title
zhengwen = d.find_element(By.CSS_SELECTOR, '[style="text-indent: 2em;"]')
zhengwen =zhengwen.text
time.sleep(1)

d = webdriver.Chrome()
d.get('http://192.168.0.125:9009/')
d.maximize_window()
time.sleep(1)

js = "window.scrollTo(0,1000);"
d.execute_script(js)
time.sleep(1)

button_denglu = d.find_element(By.LINK_TEXT,'登录')
button_denglu.click()
time.sleep(1)


username = d.find_element(By.CSS_SELECTOR, '[id="user_login"]')
password = d.find_element(By.CSS_SELECTOR, '[id="user_pass"]')
username.send_keys('admin')
password.send_keys('admin123')
button = d.find_element(By.CSS_SELECTOR, '[id="wp-submit"]')
button.click()
time.sleep(1)

more_ele = d.find_element(By.LINK_TEXT, '文章')
ActionChains(d).move_to_element(more_ele).perform()
time.sleep(1)

xw = d.find_element(By.CSS_SELECTOR, '[href="post-new.php"]')
xw.click()
time.sleep(1)

xbiaoti = d.find_element(By.CSS_SELECTOR, '[name="post_title"]')
xbiaoti.send_keys(biaoti)
zxw = d.find_element(By.CSS_SELECTOR, '[id="content_ifr"]')
d.switch_to.frame(zxw)
xzhengwen = d.find_element(By.CSS_SELECTOR, '[id="tinymce"]')
xzhengwen.send_keys(zhengwen)
time.sleep(1)
d.switch_to.default_content()
time.sleep(1)
pub = d.find_element(By.CSS_SELECTOR, '[name="publish"]')
pub.click()
time.sleep(2)